package com.ruoyi.web.controller.task;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.system.service.IPlayCountService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class TaskSchedule extends BaseController{

    private static Logger logger = LoggerFactory.getLogger(TaskSchedule.class);

    @Autowired
    private IPlayCountService playCountService;

    @Scheduled(cron = "0 5 0 ? * *")
    public void task(){
        //查出所有代理玩家id
        logger.info("开始执行定时任务...............................................................");
        List<String> gameUserIds = playCountService.getAllAgencyIds();
        for(String gameUserId:gameUserIds){
            logger.info("正在执行定时任务.........");
            List<String> stringList = playCountService.selectClubCountByCreateUser(gameUserId);
            int count=0;
            if(stringList != null){
                for(String member:stringList){
                    count += member.split(".").length;
                }
            }
            String date = DateUtils.getDate();
            Map<String,Object> map = new HashMap<>();
            map.put("clubCount",count);
            map.put("gameUserId",gameUserId);
            map.put("date",date);
            playCountService.insertAgencyClubCount(map);
        }
        logger.info("定时任务执行结束..............................................................");

    }
}
